import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "unplugin-vue-components/resolvers"
// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  plugins: [vue(),
  Components({
    resolvers: [VantResolver()],
  }),],
  server: {
    host: "127.0.0.1",
    cors: true,
    port: 8888,
    open: false, //自动打开
    proxy: {
      // 如果有统一后缀, 如api, 直接写api即可, 也不用rewrite了
      "^/api": {
        target: "https://www.vcaimao.com/f2", // 真实接口地址, 后端给的基地址
        changeOrigin: true, // 允许跨域
        secure: false,  //关键参数，不懂的自己去查
        rewrite: (path) => path.replace(/^\/api/, '')
      },
    },
  },
})
